//
//  WorldDetailTableViewCell.m
//  NineGroupProject
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "WorldDetailTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "Masonry.h"

@implementation WorldDetailTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}
- (void)createSubViews
{
    
#pragma mark - 背景图片
    self.backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5 * WID, 5 * WID, WIDTH - 10 * WID, 260 * HEI)];
    self.backgroundImageView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.backgroundImageView];
    self.backgroundImageView.userInteractionEnabled = YES;

    
#pragma mark - 图像图片
    self.image_urlImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"photo.jpg"]];
    self.image_urlImageView.frame = CGRectMake(0, 0, self.backgroundImageView.frame.size.width , self.backgroundImageView.frame.size.height - 50 * HEI);
    [self.backgroundImageView addSubview:self.image_urlImageView];
    self.image_urlImageView.userInteractionEnabled = YES;

    
#pragma mark - 标题中文
    self.name_zh_cnLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.image_urlImageView.frame.origin.x + 15 * WID, self.image_urlImageView.frame.origin.y + 5 * HEI, WIDTH - 10 * 2 * WID, 30 * HEI)];
    [self.backgroundImageView addSubview:self.name_zh_cnLabel];
    self.name_zh_cnLabel.text = @"日本概况";
    self.name_zh_cnLabel.textColor = [UIColor whiteColor];
    self.name_zh_cnLabel.font = [UIFont boldSystemFontOfSize:20];
    self.name_zh_cnLabel.numberOfLines = 0;
    
#pragma mark - 英文
    self.name_enLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.image_urlImageView.frame.origin.x + 15 * WID, self.name_zh_cnLabel.frame.origin.y + 20 * HEI, WIDTH - 10 * 2 * WID, 20 * HEI)];
    [self.backgroundImageView addSubview:self.name_enLabel];
    self.name_enLabel.textColor = [UIColor whiteColor];
    self.name_enLabel.text = @"JAPAN";
    self.name_enLabel.font = [UIFont systemFontOfSize:13];

    
#pragma mark - 行程
    self.lineButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.lineButton.frame = CGRectMake((WIDTH - 75 * WID) / 4, self.image_urlImageView.frame.size.height + 10 * HEI, 50 * WID, 50 * WID);
    self.lineButton.tag = 1001;
    [self.backgroundImageView addSubview:self.lineButton];
    [self.lineButton setImage:[UIImage imageNamed:@"iconfont-xingcheng.png"] forState:UIControlStateNormal];
    [self.lineButton addTarget:self action:@selector(lineButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.lineButton.frame.origin.x + 10 * WID, self.lineButton.frame.origin.y + 50 * HEI, 50 * WID, 20 * HEI)];
    self.lineLabel.text = @"行程";
    [self.lineLabel sizeToFit];
    self.lineLabel.font = [UIFont systemFontOfSize:13];
    self.lineLabel.textAlignment = NSTextAlignmentCenter;
    self.lineLabel.textColor = [UIColor darkGrayColor];
    [self.backgroundImageView addSubview:self.lineLabel];
    
    
#pragma mark - 旅行地
    self.placeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.placeButton.frame = CGRectMake((WIDTH - 75 * WID) / 2, self.image_urlImageView.frame.size.height + 10 * HEI, 50 * WID, 50 * WID);
    self.placeButton.tag = 1002;
    [self.backgroundImageView addSubview:self.placeButton];
    [self.placeButton setImage:[UIImage imageNamed:@"iconfont-zhuanti.png"] forState:UIControlStateNormal];
    [self.placeButton addTarget:self action:@selector(lineButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.placeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.placeButton.frame.origin.x + 10 * WID, self.placeButton.frame.origin.y + 50 * HEI, 50 * WID, 20 * HEI)];
    self.placeLabel.text = @"专题";
    self.placeLabel.font = [UIFont systemFontOfSize:13];
    self.placeLabel.textAlignment = NSTextAlignmentCenter;
    [self.placeLabel sizeToFit];
    self.placeLabel.textColor = [UIColor darkGrayColor];
    [self.backgroundImageView addSubview:self.placeLabel];

    
    
    
#pragma mark - 专题
    self.zhuantiButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.zhuantiButton.frame = CGRectMake(self.placeButton.frame.origin.x + 75 * WID, self.image_urlImageView.frame.size.height + 10 * HEI, 50 * WID, 50 * WID);
    self.zhuantiButton.tag = 1003;
    [self.backgroundImageView addSubview:self.zhuantiButton];
    [self.zhuantiButton setImage:[UIImage imageNamed:@"iconfont-mudedidianji.png"] forState:UIControlStateNormal];
    [self.zhuantiButton addTarget:self action:@selector(lineButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    self.zhuantiLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.zhuantiButton.frame.origin.x + 5 * WID, self.zhuantiButton.frame.origin.y + 50 * HEI, 50 * WID, 20 * HEI)];
    self.zhuantiLabel.text = @"目的地";
    self.zhuantiLabel.font = [UIFont systemFontOfSize:13];
    self.zhuantiLabel.textAlignment = NSTextAlignmentCenter;
    [self.zhuantiLabel sizeToFit];
    self.zhuantiLabel.textColor = [UIColor darkGrayColor];
    [self.backgroundImageView addSubview:self.zhuantiLabel];
    
    
}

- (void)setForeignModel:(ForeignModel *)foreignModel{
    
    if (_foreignModel != foreignModel) {
        _foreignModel = foreignModel;
    }

    self.name_zh_cnLabel.text = foreignModel.name_zh_cn;
    self.name_enLabel.text = foreignModel.name_en;
    
    [self.image_urlImageView sd_setImageWithURL:[NSURL URLWithString:foreignModel.image_url] placeholderImage:[UIImage imageNamed:@"loading.jpg"]];
    
}

- (void)lineButtonAction:(UIButton *)button
{
    // 点击按钮,触发协议方法(传值: tag, nameId, name)
    [self.cellDelegate pushToViewControllerTag:button.tag NameId:self.foreignModel.nameId Name:self.foreignModel.name_zh_cn];
}





- (void)awakeFromNib {
    // Initialization code
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
